<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
	<head>
		<th:block th:include="include :: header('数据源配置')"/>
	</head>
	<body>
		<div style="height: 15px;padding: 15px;background-color: #fff;">
			<span class="layui-breadcrumb">
				<a href="#">系统管理</a>
				<a><cite>数据库设置</cite></a>
			</span>
		</div>
		<div style="padding: 20px;background-color: #f2f2f2;">
			<div class="layui-row layui-col-space13">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-header">数据库配置信息列表</div>
						<div class="layui-card-body">
							<table id="dbTable" lay-filter="dbTable"></table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script id="tool" type="text/html">
			<a lay-event="editDataBase" class="layui-btn layui-btn-xs">
				<i class="layui-icon layui-icon-edit"></i>
			</a>
			<a lay-event="delDataBase" class="layui-btn layui-btn-xs layui-btn-danger">
				<i class="layui-icon layui-icon-delete"></i>
			</a>
		</script>
		<script id="toolbar" type="text/html">
			<div class="layui-btn-container">
				<a lay-event="addDataBase" class="layui-btn layui-btn-sm layui-btn-normal">
					<i class="layui-icon layui-icon-addition"></i>新增数据库配置
				</a>
			</div>
		</script>
		<script id="isUse" type="text/html">
			<input type="checkbox" disabled name="isUse" value="{{d.isUse}}" lay-skin="switch"
			lay-text="当前使用|未使用" lay-filter="isUse" {{d.isUse == '0'?"checked":""}} >
		</script>
		<th:block th:include="include :: footer"/>
		<script>

			layui.use(['element','table','layer'],function(){
				var element = layui.element,table = layui.table
				layer = layui.layer,$ = layui.jquery;

				table.render({
                    url:'/dsc/find',
					elem: '#dbTable',
					toolbar:'#toolbar',
					defaultToolbar:[],
					cols: [
							[
						{type:'radio'},
						{type:'numbers'},
						{field:'dbName',title:'数据源名字',width:150},
						{field:'dbType',title:'数据库名字',width:80},
						{field:'url',title:'数据库URL',width:350},
						{field:'username',title:'登录名',width:80},
						{field:'password',title:'登录密码',width:100},
						{field:'driver',title:'数据库驱动',width:200},
						{field:'isUse',title:'是否默认使用',width:150,templet:'#isUse'},
						{fixed:'right',title:'操作',width:150,toolbar:'#tool',align:'center'}
					]
					],
					height:'full-170',
					page:true
				});

				//表格头部工具条监听
				table.on('toolbar(dbTable)',function(obj){
					var event = obj.event;
					switch(event){
						case 'addDataBase':
							layer.open({
								type:2,
								title:'新增数据源',
								content:'/dsc/addPage',
								area:['700px','450px']
							});
						break;
					}
				});

				table.on('tool(dbTable)',function (obj) {
                    var event = obj.event;
					var id = obj.data.id;
                    switch(event){
                        case 'editDataBase':
                            layer.open({
                                type:2,
                                title:'编辑数据源',
                                content:'/dsc/editPage/'+id,
                                area:['700px','450px']
                            });
                        	break;
						case 'delDataBase':
							layer.confirm('真的要删除该条记录?',{icon:3,title:'系统警告'},function(i){
								$.ajax({
									type:'get',
									url:'/dsc/remove/'+id,
									dataType:'json',
									success:function (result) {
										layer.msg(result.msg);
										obj.del();//物理删除行
									}
								});
							});
							break;
                    }
                })
			});

		</script>

	</body>
</html>
